package com.stone.cat.web.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.stone.cas.pojo.CasUser;
import com.stone.cat.common.constant.ViewConstant;
import com.stone.cat.common.util.HttpClientUtil;
import com.stone.cat.common.util.MapUtil;
import com.stone.cat.facade.pojo.request.LoginRequestDTO;
import com.stone.cat.facade.pojo.response.CatBaseResponseDTO;
import com.stone.cat.facade.service.UserManagerService;
import com.stone.cat.persist.config.CASConfig;
import com.stone.spring.core.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * Created by 喵 on 2018/2/6.
 */
@Controller
@RequestMapping(value = "/user")
public class UserController {

    @Autowired
    private UserManagerService userManagerService;

    @GetMapping(value = "/login")
    public String login() {
        return ViewConstant.LOGIN;
    }

    @PostMapping(value = "/login")
    public String login(LoginRequestDTO requestDTO, HttpSession session) {
        CatBaseResponseDTO responseDTO = this.userManagerService.login(requestDTO);
//        if(responseDTO.getCode() == 0){
//
//        }
        return null;
    }


    @GetMapping("getSession")
    @ResponseBody
    public String testSession(HttpSession session) {
        System.out.println("sessionId :  " + session.getAttribute("user"));
        return session.getId();
    }


    @GetMapping("setSession")
    public void testSession2(HttpSession session) {
        session.setAttribute("userName", "userName");
    }


}
